# -*- coding: utf-8 -*-
print("""
# File            :  client.py
# Author          :  电科院吴彦祖
# Create Time     :  2025.05.07 17:06:23
# Python Version  :  3.8.10
    ————MAN！What can i say?
""")

import socket
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad

# 加密密钥，必须是16、24或32字节
key = b'1234567891234567'
# 初始化向量，必须是16字节
iv = b'1234567891234567'

def encrypt_message(message):
    cipher = AES.new(key, AES.MODE_CBC, iv)
    encrypted = cipher.encrypt(pad(message.encode('utf-8'), AES.block_size))
    return iv + encrypted

# 新建Socket，实例化
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 连接服务器
#实验数据：172.20.10.9 #一般：localhost
client_socket.connect(('172.20.10.9', 8888))

# 从文件读取内容
with open("client_input.txt", "r", encoding="utf-8") as file:
    message = file.read()

# 加密消息
encrypted_message = encrypt_message(message)
client_socket.send(encrypted_message)

# 反馈
data = client_socket.recv(1024)
print("服务端回答：", data.decode("utf-8"))

#关闭连接
client_socket.close()
